package cn.lycode.system.service.impl;

import cn.lycode.common.core.domain.model.ConditionDTO;
import cn.lycode.common.core.domain.model.SelectIdsDTO;
import cn.lycode.common.core.page.PageResult;
import cn.lycode.common.core.page.PageUtil;
import cn.lycode.system.domain.dto.sysdict.SysDictTypeAddDTO;
import cn.lycode.system.domain.dto.sysdict.SysDictTypeUpDTO;
import cn.lycode.system.domain.entity.SysDictType;
import cn.lycode.system.mapper.SysDictTypeMapper;
import cn.lycode.system.service.SysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Title: SysDictServiceImpl
 * @Author lyg
 * @Date 2024/7/16 15:48
 * @description:
 */
@Service
@RequiredArgsConstructor
public class SysDictTypeServiceImpl implements SysDictTypeService {

    private final SysDictTypeMapper dictTypeMapper;

    @Override
    public PageResult<SysDictType> list(ConditionDTO dto) {
        PageUtil.startPage(dto);
        List<SysDictType> dictTypeList = dictTypeMapper.list(dto);
        return PageUtil.getPageResult(dictTypeList);
    }


    @Override
    public int add(SysDictTypeAddDTO dto) {
        SysDictType sysDictType = dto.buildEntity();
        return dictTypeMapper.insertDictType(sysDictType);
    }

    @Override
    public SysDictType detail(Long id) {
        return dictTypeMapper.selectSysDictTypeById(id);
    }

    @Override
    public int update(SysDictTypeUpDTO dto) {
        SysDictType sysDictType = dto.buildUpEntity();
        return dictTypeMapper.updateDictType(sysDictType);
    }

    @Override
    public int remove(SelectIdsDTO ids) {
        return dictTypeMapper.removeByIdList(ids.getIds());
    }

    /**
     * 锁定后，记录不能删除不能修改
     */
    @Override
    public int lock(SelectIdsDTO dto) {
        return dictTypeMapper.lockDictTypeByIdList(dto.getIds());
    }

    @Override
    public List<SysDictType> selectOptionsType() {
        return dictTypeMapper.list(new ConditionDTO());
    }

}
